using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace CampaignWP7.Base
{
    class CollideBox
    {
        public Vector2 leftTop;
        public Vector2 rightBottom;
        public Vector2 center;

        public CollideBox(Vector2 lt, Vector2 rb)
        {
            leftTop = lt;
            rightBottom = rb;
            center = (leftTop + rightBottom)/2;
            //offset = c;
        }

        public bool Intersects(CollideCircle circle)
        {
            Vector2 v = circle.center - center;
            if (v.LengthSquared() < circle.radiusSquared)
            {
                return true;
            }
            Vector2 vdir = center - circle.center;
            vdir.Normalize();
            Vector2 vOnRound = circle.center + vdir * circle.radius;
            return Intersects(vOnRound);
        }
        public bool Intersects(Vector2 c)
        {
            return !(c.X < leftTop.X ||
                    c.X > rightBottom.X ||
                    c.Y < rightBottom.Y ||
                    c.Y > leftTop.Y);
        }

        public void SetPos(Vector2 pos)
        {            
            Vector2 ltoffset = center - leftTop;
            Vector2 rboffset = center - rightBottom;
            center = pos;
            leftTop = center + ltoffset;
            rightBottom = center + rboffset;
        }
    }
}
